package com.neusoft.mapper;

import com.neusoft.domain.TransactionRecordPO;
import com.neusoft.domain.VirtualWallet;
import com.neusoft.domain.VirtualWalletPO;
import org.apache.ibatis.annotations.*;

import java.math.BigDecimal;

@Mapper
public interface ClientWalletMapper {
    @Select("SELECT * FROM wallets WHERE user_id = #{userId}")
    VirtualWalletPO findById(@Param("userId") Long walletId);

    @Update("UPDATE wallets SET balance = #{balance} WHERE id = #{id}")
    void updateBalance(@Param("id") Long id, @Param("balance") BigDecimal balance);

    @Insert("INSERT INTO transaction_records (wallet_id, amount, type, timestamp) VALUES (#{walletId}, #{amount}, #{type}, #{timestamp})")
    void insertTransactionRecord(TransactionRecordPO record);

    @Update("UPDATE wallets SET balance = #{balance}, usedCredit = #{usedCredit} WHERE user_id = #{userId}")
    void updateWallet(@Param("userId") Long walletId,
                      @Param("balance") BigDecimal balance,
                      @Param("usedCredit") BigDecimal usedCredit);

    @Update("UPDATE wallets SET penalty_amount = #{newPenalty} WHERE user_id = #{userId}")
    void updatePenalty(@Param("walletId") Long walletId, @Param("newPenalty") BigDecimal newPenalty);

    // 插入一个新的钱包记录
    @Insert("INSERT INTO wallets(user_id, balance, credit_limit, used_credit, penalty_amount) VALUES(#{userId}, #{balance}, #{creditLimit}, #{usedCredit}, #{penaltyAmount})")
    void insertWallet(VirtualWallet wallet);

    // 根据用户ID查询钱包
    @Select("SELECT * FROM wallets WHERE user_id = #{userId}")
    VirtualWallet getWalletByUserId(Long userId);

    // 获取用户的信用额度
    @Select("SELECT credit_limit FROM wallets WHERE user_id = #{userId}")
    BigDecimal getCreditLimit(Long userId);
    @Select("SELECT balance FROM wallets WHERE user_id = #{userId}")
    BigDecimal getBalance(Long userId);
}